﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeHouse.Server.Dto;
namespace LeHouse.Server.Dal
{
    /// <summary>
    /// 建筑公共部位状况的DAL操作层
    /// </summary>
    public class Collateral_FacilityDAL : GenericBaseDAL<Collateral_Facility>
    {
        /// <summary>
        /// 根据报告号去查询建筑公共部位是否有该条记录
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public int count(string P_ReportNumber)
        {
            int C_projectcount;
            string sql = @"select count(F_TypesID) from t_Facility  where P_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    C_projectcount = Convert.ToInt32(cmd.ExecuteScalar());
                }
                return C_projectcount;
            }
        }

        /// <summary>
        /// 根据报告号去查询建筑公共部位状况的信息
        /// </summary>
        /// <param name="P_ReportNumber"></param>
        /// <returns></returns>
        public Collateral_Facility Facilitybyid(string P_ReportNumber)
        {
            Collateral_Facility munity = new Collateral_Facility();
            string sql = @"select * from t_Facility  where P_ReportNumber=@P_ReportNumber ";
            using (var cnn = DbConnection)
            {
                using (var cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    var p = cmd.CreateParameter();
                    p.ParameterName = "@P_ReportNumber";
                    p.Value = P_ReportNumber;
                    cmd.Parameters.Add(p);
                    var reader = cmd.ExecuteReader();
                    try
                    {
                        while (reader.Read())
                        {
                            munity.T_ReportNumber = reader["P_ReportNumber"].ToString();
                            munity.T_StructureID = Convert.ToInt32(reader["F_structureID"]);
                            munity.T_TypesID = Convert.ToInt32(reader["F_TypesID"]);
                            munity.T_FacadeID = Convert.ToInt32(reader["F_facadeID"]);
                            munity.T_CommonalityID = Convert.ToInt32(reader["F_commonalityID"]);
                            munity.T_ElevatorID = Convert.ToInt32(reader["F_elevatorID"]);
                            munity.T_SupplyID = Convert.ToInt32(reader["F_supplyID"]);
                            munity.T_WaterID = Convert.ToInt32(reader["F_waterID"]);
                            munity.T_HeatingID = Convert.ToInt32(reader["F_heatingID"]);
                            munity.T_EntranceID = Convert.ToInt32(reader["F_entranceID"]);
                            munity.T_Else = reader["F_else"].ToString();
                          //  munity.T_StructureID = Convert.ToInt32(reader["F_state"]);
                        }
                    }
                    finally
                    {
                        reader.Close();
                    }
                }
                return munity;
            }
        }
    }
}
